﻿using System;
using System.Collections.Generic;
using ZyGames.DZPocker.Model;
using ZyGames.Framework.Cache.Generic;
using ZyGames.Framework.Game.Cache;
using ZyGames.Framework.Game.Context;
using ZyGames.Framework.Game.Contract;
using ZyGames.Framework.Game.Contract.Action;
using ZyGames.Framework.Game.Lang;
using ZyGames.Framework.Game.Service;
using System.Linq;
using ZyGames.DZPocker.Bll.Logic;
using ZyGames.DZPocker.Script;
using ZyGames.Framework.Net;
using ZyGames.Framework.Common.Serialization;
using System.Threading;
using ZyGames.DZPocker.Tools;

namespace ZyGames.DZPocker.Script.CsScript.Action
{
	/// <summary>
	/// 请求玩家数据
	/// </summary>
	public class Action30040 : BaseAction
	{
		private int userId;
		private int totalPeriodsInt = 0;
		/// <summary>
		/// 总局数
		/// </summary>
		//private string totalPeriods;
		private int winPeriodsInt = 0;
		/// <summary>
		/// 胜利局数
		/// </summary>
		//private string winPeriods;
		private int winOppsInt = 0;
		/// <summary>
		/// 胜率100%
		/// </summary>
		//private string winOpps;
		private int forgiveByAddChipOppsInt = 0;
		/// <summary>
		/// 遇到加注弃牌率
		/// </summary>
		//private string forgiveByAddChipOpps;
		//private int addChipBeforeShowCardOppsInt = 0;
		//加注率
		private int addChipOppsInt = 0;
		/// <summary>
		/// 翻牌前加注率
		/// </summary>
		//private string addChipBeforeShowCardOpps;
		private int threeBETInt = 0;
		/// <summary>
		/// 3BET
		/// </summary>
		//private string threeBET;
		private int showCardsOppsInt = 0;
		/// <summary>
		/// 摊牌率
		/// </summary>
		//private string showCardsOpps;
		private int winOppsByShowCardsInt = 0;
		/// <summary>
		/// 摊牌胜率
		/// </summary>
		//private string winOppsByShowCards;
		private int lookAndShowCardsOppsInt = 0;
		/// <summary>
		/// 看翻牌率
		/// </summary>
		//private string lookAndShowCardsOpps;
		private int enterTableOppsInt = 0;
		/// <summary>
		/// 入局率
		/// </summary>
		//private string enterTableOpps;
		private int forgiveByThreeBETOppsInt = 0;
		/// <summary>
		/// 遇3BET弃牌率
		/// </summary>
		//private string forgiveByThreeBETOpps;
		/// <summary>
		/// 判定选手类型
		/// </summary>
		private string judge;
		/// <summary>
		/// 好友印象
		/// </summary>
		private string friendsImpression;
		public Action30040(HttpGet actionGetter)
			: base((short)ActionType.DZApplyPlayerData, actionGetter)
		{
		}
		public override bool GetUrlElement()
		{
			if (httpGet.GetInt("UserId", ref userId))
			{
				return true;
			}
			return false;
		}

		public override bool TakeAction()
		{

			var currentGameUser = GameTable.Current.GetUser(userId);
			if (currentGameUser == null)
			{
				Tool.WriteWarmingLine("消息30040玩家不存在");
				return false;
			}


			//******************测试数据*******************8
			//currentGameUser.TotalPeriodsCount = 100;
			//currentGameUser.WinPeriodsCount = 60;

			//currentGameUser.EnterTableCount = 30;
			//currentGameUser.ShowCardsCount = 35;
			//currentGameUser.WinTimesByShowCardsCount = 44;
			//currentGameUser.AddChipCount = 63; //加注率
			//currentGameUser.ThreeBETCount = 56;  //3bet f
			//currentGameUser.ForgiveByThreeBETCount = 56; //3bet弃牌

			this.totalPeriodsInt = currentGameUser.TotalPeriodsCount;
			if (this.totalPeriodsInt != 0)
			{
				//获胜次数
				this.winPeriodsInt = currentGameUser.WinPeriodsCount;
				//胜率
				this.winOppsInt = Convert.ToInt32(Math.Floor(Convert.ToDouble(((double)winPeriodsInt / totalPeriodsInt) * 100)));
				//this.forgiveByAddChipOppsInt = Convert.ToInt32(Math.Floor(Convert.ToDouble(((double)currentGameUser.ForgiveByAddChipCount / totalPeriodsInt) * 100)));
				//this.addChipBeforeShowCardOppsInt = Convert.ToInt32(Math.Floor(Convert.ToDouble(((double)currentGameUser.AddChipBeforeShowCardCount / totalPeriodsInt) * 100)));
				this.addChipOppsInt = Convert.ToInt32(Math.Floor(Convert.ToDouble(((double)currentGameUser.AddChipCount / totalPeriodsInt) * 100)));
				this.threeBETInt = Convert.ToInt32(Math.Floor(Convert.ToDouble(((double)currentGameUser.ThreeBETCount / totalPeriodsInt) * 100)));
				this.showCardsOppsInt = Convert.ToInt32(Math.Floor(Convert.ToDouble(((double)currentGameUser.ShowCardsCount / totalPeriodsInt) * 100)));
				this.winOppsByShowCardsInt = Convert.ToInt32(Math.Floor(Convert.ToDouble(((double)currentGameUser.WinTimesByShowCardsCount / totalPeriodsInt) * 100)));
				//this.lookAndShowCardsOppsInt = Convert.ToInt32(Math.Floor(Convert.ToDouble(((double)currentGameUser.LookAndShowCardsCount / totalPeriodsInt) * 100)));
				//入局率
				this.enterTableOppsInt = Convert.ToInt32(Math.Floor(Convert.ToDouble(((double)currentGameUser.EnterTableCount / totalPeriodsInt) * 100)));
				this.forgiveByThreeBETOppsInt = Convert.ToInt32(Math.Floor(Convert.ToDouble(((double)currentGameUser.ForgiveByThreeBETCount / totalPeriodsInt) * 100)));
			}
			this.judge = "挑选手牌，进攻性弱型选手";
			this.friendsImpression = "进攻性弱";
			return true;
		}

		public override void BuildPacket()
		{
			this.PushIntoStack(this.totalPeriodsInt);
			this.PushIntoStack(this.winPeriodsInt);
			this.PushIntoStack(this.winOppsInt);

			this.PushIntoStack(this.enterTableOppsInt); //入局
			this.PushIntoStack(this.showCardsOppsInt); //摊牌
			this.PushIntoStack(this.winOppsByShowCardsInt);//摊牌胜利
			this.PushIntoStack(this.addChipOppsInt);//加注
			this.PushIntoStack(this.threeBETInt); //3bet f
			this.PushIntoStack(this.forgiveByThreeBETOppsInt); //3bet弃牌
		}
	}
}
